using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyUnityLib.Tool;
using MyUnityLib.ClassExtension;
using System;

namespace ProductExpirationAssistant
{
    public class DataManager : SingleMono<DataManager>
    {
        public DateTime curDate;
        public FunctionType functionType;

        /// <summary>下架生产日期面板是否锁定UI响应</summary>
        public bool lockProductionDatePanel
        {
            get => PlayerPrefs.GetInt("lockProductionDatePanel", 0) == 0 ? false : true;
            set => PlayerPrefs.SetInt("lockProductionDatePanel", value ? 1 : 0);
        }

        /// <summary>下架日期面板是否锁定UI响应</summary>
        public bool lockOffShelfDatePanel
        {
            get => PlayerPrefs.GetInt("lockOffShelfDatePanel", 0) == 0 ? false : true;
            set => PlayerPrefs.SetInt("lockOffShelfDatePanel", value ? 1 : 0);
        }

        protected override void Awake()
        {
            base.Awake();

            GameObject.Find("Canvas").transform.FindComponentByPath<TipPopupPanel>("TipPopupPanel").Init();
            OffShelfProductionDateQueryDatabase.ins.Init();
            OffShelfDateQueryDatabase.ins.Init();

            curDate = GetCurDate();
        }

        /// <summary>使用系统日期</summary>
        public void ResetCurDate()
        {
            curDate = GetCurDate();
        }

        /// <summary>获得当前日期</summary>
        private DateTime GetCurDate()
        {
            var date = DateTime.Now;
            return new DateTime(date.Year, date.Month, date.Day);
        }
    }
}